/*
 * Copyright (c) 2011-2020, baomidou (jobob@qq.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * https://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.baomidou.mybatisplus.generator.config.querys;

import com.baomidou.mybatisplus.annotation.DbType;

/**
 * Oracle 表数据查询
 *
 * @author hubin
 * @since 2018-01-16
 */
public class DMQuery extends AbstractDbQuery {


    @Override
    public DbType dbType() {
        return DbType.DM;
    }


    @Override
    public String tablesSql() {
        return "select * from user_tables";
    }

    public static String getPrimaryKey(){
        return "select column_name\n" +
                "from user_cons_columns\n" +
                "where table_name='%s' and constraint_name in\n" +
                "                            (select constraint_name\n" +
                "                             from user_constraints\n" +
                "                             where table_name='%s' and constraint_type='P')";
    }


    @Override
    public String tableFieldsSql() {
        return " SELECT\n" +
                "      b.COLUMN_NAME,b.DATA_TYPE,a.COMMENTS\n" +
                "  FROM\n" +
                "      USER_TAB_COLUMNS b,USER_COL_COMMENTS a\n" +
                "  WHERE\n" +
                "      b.TABLE_NAME = '%s' AND b.TABLE_NAME = a.TABLE_NAME AND b.COLUMN_NAME = a.COLUMN_NAME";
    }


    @Override
    public String tableName() {
        return "TABLE_NAME";
    }


    @Override
    public String tableComment() {
        return "COMMENTS";
    }


    @Override
    public String fieldName() {
        return "COLUMN_NAME";
    }


    @Override
    public String fieldType() {
        return "DATA_TYPE";
    }


    @Override
    public String fieldComment() {
        return "COMMENTS";
    }


    @Override
    public String fieldKey() {
        return "KEY";
    }




}
